package com.zhang.zxx.boot.common.core.event;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.Date;

/**
 * LogEvent:日志事件
 *
 * @author zhangxiaoxiang
 * @date 2021/11/27
 */

@Slf4j
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class LogEvent implements Serializable {
    /**
     * 唯一标识
     */
    private String id;
    /**
     * 接口名称
     */
    private String apiName;
    /**
     * 请求参数
     */
    private Object requestParam;

    /**
     * 返回数据
     */
    private Object responseData;
    /**
     * 发布时间
     */
    private String eventTime = DateUtil.formatDateTime(new Date());

    /**
     * 是否完成
     */
    private boolean finish = true;

    public static LogEvent builder(Object requestParam,Object responseData){
        return new LogEvent().setId(IdUtil.getSnowflake().nextIdStr()).setRequestParam(requestParam).setResponseData(responseData);
    }
}
